package cn.com.zcode.dic.control;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.com.zcode.core.cache.ApplicationCacheAware;
import cn.com.zcode.dic.model.Dictionary;
import cn.com.zcode.dic.service.DictionaryService;

import java.util.LinkedHashMap;

public class GlobalDictionaryInit implements ApplicationCacheAware {
	private DictionaryService dictionaryService;

	public void load(ApplicationCache manager) {
		System.out.println("初始化全局数据......");
		List<Dictionary> dics = dictionaryService.findInitDictionary();
		if (dics != null) {
			if (dics.isEmpty()) {
				Dictionary pmp = new Dictionary("pmp", "PMP", null, 1, true);
				Map<String, String> map = new LinkedHashMap<String, String>();
				List<String> list = new ArrayList<String>();
				list.add("综合题目");
				list.add("整合管理");
				list.add("范围管理");
				list.add("时间管理");
				list.add("成本管理");
				list.add("质量管理");
				list.add("人力资源管理");
				list.add("沟通管理");
				list.add("风险管理");
				list.add("采购管理");
				list.add("干系人管理");
				list.add("其它");
				int num2 = 0;
				for (String string : list) {
					num2++;
					map.put("pmp_" + num2, string);
				}

				dics.add(pmp);
				dictionaryService.addDictionary(pmp);
				Set<String> set = map.keySet();
				int num = 1;
				for (String string : set) {
					Dictionary pmp1 = new Dictionary(string, map.get(string), pmp, num++, true);
					dictionaryService.addDictionary(pmp1);
					dics.add(pmp1);

				}

			}

			for (Dictionary dictionary : dics) {
				manager.addDictionary(dictionary);
			}
		}
	}

	public DictionaryService getDictionaryService() {
		return dictionaryService;
	}

	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}

}
